package com.example.service.webhook.business.carrier.repository;

import com.example.service.webhook.business.carrier.entity.MobileSmsEntity;
import com.example.service.webhook.business.carrier.entity.report.ReportEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 运营商套餐适用情况
 * ClassName: PackageUsageRepository
 * date: 2016年7月19日 下午6:29:23
 *
 * @author yuandong
 * @since JDK 1.6
 */
@Repository
public class ReportDataRepository extends BaseDAO<ReportEntity> {

    @Resource(name = "templateCarrier")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveReportData(ReportEntity entity) throws Exception {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }

    public void deleteReportData(String userId, String mobile) {
        String sql = "delete from t_reportdata where userId=? and mobile=?";
        this.delete(sql, new Object[]{userId, mobile});
    }

    public ReportEntity getReportData(String userId, String mobile) throws Exception {
        String sql = "";
        String tableName = "t_reportdata";
        sql = "select * from " + tableName + " where userId=? and mobile=?";
        ReportEntity pojo = null;
        try {
            pojo = (ReportEntity) queryOne(sql, new Object[]{userId, mobile}, new ReportEntity());
        } catch (EmptyResultDataAccessException e) {
            return null;
        }

        return pojo;
    }


}
